local hx__niyongwoyong = fk.CreateSkill {
  name = "hx__niyongwoyong",
}


hx__niyongwoyong:addEffect(fk.CardUsing, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    local used = player:getTableMark("@$hx_nywy_used-turn")
    if used == nil then
      used = {}
    end
    return player:hasSkill(hx__niyongwoyong.name) and data.card and not table.contains(used, data.card.trueName)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local cardName = data.card.trueName
    local originalTarget = data.tos[1]
    local cantos = table.filter(room:getAlivePlayers(), function(p)
      return p.id ~= originalTarget
    end)
    if #cantos == 0 then return false end
    local target_p = room:askToChoosePlayers(player, {
      targets = cantos,
      prompt = "#hx__niyongwoyong-choose:::"..data.card:toLogString(),
      max_num = 1,
      min_num = 1,
      cancelable = true,
      skill_name = hx__niyongwoyong.name,
    })
    if #target_p > 0 then
      event:setCostData(self, {
        newTarget = target_p[1],
        cardName = cardName
      })
      return true
    end
    return false
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local costData = event:getCostData(self)
    data.tos = {costData.newTarget}
    local used = player:getTableMark("@$hx_nywy_used-turn")
    if used == nil then
      used = {}
    end
    table.insertIfNeed(used,costData.cardName)
    room:setPlayerMark(player, "@$hx_nywy_used-turn",used)
  end
})


return hx__niyongwoyong